layui.define(["jquery"], function (exports) {
    //QQ1147361223提供技术驱动
    var form = layui.form,
        layer = layui.layer,
        table = layui.table,
        laydate = layui.laydate,
        upload = layui.upload,
        element = layui.element,
        laytpl = layui.laytpl,
        tableSelect = layui.tableSelect,
        util = layui.util;
        $ = layui.jquery,
            body_width = document.body.clientWidth,
            body_height = document.body.clientHeight,clienWidth = '100%',clientHeight = '100%';
    if ( body_width >= 800 &&  body_height >= 600) {
        clienWidth = '800px';
        clientHeight = '600px';
    }

    var admin= {
        open:function (title,url,width=null,height=null,cancelCallback=null){
            layer.open({
                title: title,type: 2, area: [width?width:clienWidth, height?height:clientHeight],
                content: url,
                maxmin: true,
                moveOut: true,
                shadeClose: false,
                end: function(){
                    // 层销毁后触发的回调
                    if (cancelCallback) {
                        cancelCallback();
                    }
                }
            });
        },
        listen: function () {
            $('body').on('click', '[data-open]', function () {
                var clienWidth = $(this).attr('data-width'),
                    clientHeight = $(this).attr('data-height'),
                    dataFull = $(this).attr('data-full'),
                    cancelCallback=$(this).attr('cancel'),
                    url = $(this).attr('data-open');
                if (clienWidth === undefined || clientHeight === undefined) {
                    var width = document.body.clientWidth,
                        height = document.body.clientHeight;
                    if (width >= 800 && height >= 600) {
                        clienWidth = '800px';
                        clientHeight = '600px';
                    } else {
                        clienWidth = '100%';
                        clientHeight = '100%';
                    }
                }
                if (dataFull === 'true') {
                    clienWidth = '100%';
                    clientHeight = '100%';
                }
                layer.open({
                    title: $(this).attr('data-title'),type: 2, area: [clienWidth, clientHeight],
                    content: url,
                    maxmin: true,
                    moveOut: true,
                    shadeClose: false
                });
            });
        }
    };
    // return admin;
    //输出接口
    exports('easyadmin',admin);
});
